package com.zbhk.qc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zbhk.qc.dto.SmallProgramVO;
import com.zbhk.qc.entity.VdSmallProgram;
import com.zbhk.qc.mapper.VdSmallProgramMapper;
import com.zbhk.qc.service.SmallProgramServer;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhulenan on 2020/7/22 11:14
 */
@Service
public class SmallProgramServerImpl implements SmallProgramServer {

    @Autowired
    private VdSmallProgramMapper vdSmallProgramMapper;


    @Override
    public IPage<VdSmallProgram> getListPage(String name, String appid,Integer pageSize, Integer pageNumber) {
        IPage<VdSmallProgram> page = new Page<>(pageNumber,pageSize);
        List<VdSmallProgram> list = vdSmallProgramMapper.getListPage(name,appid,page);
        page.setRecords(list);
        return page;
    }

    @Override
    public void save(SmallProgramVO smallProgramVO) {
        VdSmallProgram smallProgram = new VdSmallProgram();
        BeanUtils.copyProperties(smallProgramVO,smallProgram);
        vdSmallProgramMapper.insert(smallProgram);
    }

    @Override
    public VdSmallProgram update(SmallProgramVO smallProgramVO) {
        VdSmallProgram smallProgram = vdSmallProgramMapper.selectById(smallProgramVO.getId());
        BeanUtils.copyProperties(smallProgramVO,smallProgram);
        vdSmallProgramMapper.updateById(smallProgram);
        return smallProgram;
    }

    @Override
    public void delete(Long id) {
        vdSmallProgramMapper.deleteById(id);
    }

    @Override
    public VdSmallProgram get(Long id) {
        VdSmallProgram smallProgram = vdSmallProgramMapper.selectById(id);
        return smallProgram;
    }
}

  